package com.dkd.sbtz.domain;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import com.dkd.sbtz.domain.vo.spare.SpecialItemDTO;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.dkd.common.annotation.Excel;
import com.dkd.common.core.domain.BaseEntity;

/**
 * 工单列表对象 asset_work_order
 * 
 * @author xzj
 * @date 2025-09-09
 */
import org.apache.ibatis.type.Alias;
import org.springframework.format.annotation.DateTimeFormat;

@Alias("AssetWorkOrder")
@Data
public class AssetWorkOrder extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 工单ID */
    private Long id;

    /** 工单编号 */
    @Excel(name = "工单编号")
    private String woCode;

    @Excel(name = "工单名称")
    private String woName;

    @Excel(name = "工单内容")
    private String woContent;

    /** 工单标题 */
    @Excel(name = "工单标题")
    private String title;

    /** 工单类型 */
    @Excel(name = "工单类型")
    private String orderType;

    @Excel(name = "故障类型")
    private Integer faultType;

    /** 紧急程度 */
    @Excel(name = "紧急程度")
    private Integer urgency;

    /** 设备名称 */
    @Excel(name = "设备名称")
    private Long equipmentId;

    /** 设备编号 */
    @Excel(name = "设备编号")
    private Long spareId;

    /** 故障/需求描述 */
    @Excel(name = "故障/需求描述")
    private String faultDesc;

    /** 报修人 */
    @Excel(name = "报修人")
    private String requesterId;

    /** 派单人 */
    @Excel(name = "派单人")
    private String dispatcherId;

    /** 接修人 */
    @Excel(name = "接修人")
    private String receiverId;

    /** 工单状态 */
    @Excel(name = "工单状态")
    private String status;

    /** 工单来源 */
    @Excel(name = "工单来源")
    private String source;

    /** 需求报送时间 */
//    @JsonFormat(pattern = "yyyy-MM-dd")
//    @Excel(name = "故障时间", width = 30, dateFormat = "yyyy-MM-dd")
//    private Date submitTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime submitTime;

    /** 工单创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "工单创建时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "工单创建时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date updateTime;

    /** 计划开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "计划开始时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date planStartTime;

    /** 计划完成时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "计划完成时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date planEndTime;

    /** 实际开始时间 */
//    @JsonFormat(pattern = "yyyy-MM-dd")
//    @Excel(name = "实际开始时间", width = 30, dateFormat = "yyyy-MM-dd")
//    private Date actualStartTime;
//
//    /** 实际完成时间 */
//    @JsonFormat(pattern = "yyyy-MM-dd")
//    @Excel(name = "实际完成时间", width = 30, dateFormat = "yyyy-MM-dd")
//    private Date actualEndTime;


//    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    @Excel(name = "实际开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
//    private Date actualStartTime;
//
//    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    @Excel(name = "实际完成时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
//    private Date actualEndTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime actualStartTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime actualEndTime;

    /** 系统计算的优先级 */
    private Long priorityScore;


    /** 是否全量替换备件（编辑时 true=用本次列表覆盖；空列表=清空） */
    private Boolean replaceSpares;

    /** 备件清单（needSpare=0 时前端会传空数组） */
    private List<SpareItem> spares;
    @Data
    public static class SpareItem {
        private Long spareId;
        private Integer qty;
        private Long assetId; // 如果冗余，可后端忽略，用 equipmentId 映射
    }


    // 一对多：附件列表
    private List<AssetOrderAttachment> attachments;

    // 一对一：设备详情
    private AssetNodeDTO node;
    @Data
    public static class AssetNodeDTO {
        private Long id;
        private String name;
        private String code;
        private String model;
        private String specification;
        private String brand;
        // ...按需增加
    }

    // 一对多：备件明细（含数量）
    private List<OrderSpareDTO> spareInfos;
    @Data
    public static class OrderSpareDTO {
        private Long orderId;
        private Long spareId;
        private Integer qty;

        // 展示字段来自 asset_spare
        private String code;
        private String name;
        private Integer type;
        private Integer orderDate;
        private Integer minStock;
        private Integer maxStock;
        private Integer stockTotal;
        private Integer stockAvailable;
    }


    private List<SpecialItemDTO> specialItems;




}
